package com.huaxia.day19;

public class StringTestN {
    public static void main(String[] args) {

        testString();
        testString1();
        testStringBuffer();
        testEqual();
    }

    static void testString() {
        String hello = new String("hello,hello");
        char c = hello.charAt(1);
        System.out.println(c);
        System.out.println(hello.length());
        System.out.println(hello.equalsIgnoreCase("hello,HELLO"));
        System.out.println(hello.indexOf("ll"));
        System.out.println(hello.concat("world"));
        System.out.println(hello.split(",")[0]);

        System.out.println(hello.replaceAll("ll", "HH"));
        System.out.println(hello.toUpperCase());
    }

    static void testStringBuffer() {
        // todo 线程安全 ， append 返回sb对象
        StringBuffer buffer = new StringBuffer();
        buffer.append("hello");
        buffer.append(",")
                .append("world")
                .append("!");
        System.out.println(buffer.toString());

        StringBuilder sb = new StringBuilder("hello");
        sb.append(",world");
        System.out.println(sb.toString());
    }

    static void testString1() {
        String s = "Awe1x#123#456#zjhu";
        int n = s.indexOf("#");
        int k = s.indexOf("#", n + 1);
        String s2 = s.substring(n + 1, k);
        System.out.println(s2);
    }

    static void testEqual() {
        String s1 = new String("abc");
        String s2 = new String("abc");
        boolean b1 = s1.equals(s2);
        boolean b2 = s1 == s2;
        System.out.print(b1 + "   " + b2);

    }
}
